<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
        小程序商城管理平台
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../css/x-admin.css" media="all">

</head>
<style>
    #mold1 {
        background: papayawhip;
        width: 100px;
        height: 30px;
        overflow: hidden;
    }

    #mold1 select {
        background: transparent;
        border: none;
        padding-left: 10px;
        width: 120px;
        height: 100%;
    }

    #mold2 {
        background: papayawhip;
        width: 100px;
        height: 30px;
        overflow: hidden;
    }

    #mold2 select {
        background: transparent;
        border: none;
        padding-left: 10px;
        width: 120px;
        height: 100%;
    }

    #div1 {
        margin: auto;
        bottom: 20px;
        width: 300px;
        top: 20px;
    }
    #mold3 {
        background: papayawhip;
        width: 100px;
        height: 30px;
        overflow: hidden;
    }

    #mold4 {
        background: papayawhip;
        width: 100px;
        height: 30px;
        overflow: hidden;
    }
    #c{
        position:absolute;
        bottom:0;
        right:0;
    }
</style>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header header header-demo">
        <div class="layui-main">
            <a class="logo" href="index.html">
                一站式商城管理平台
            </a>
            <ul class="layui-nav" lay-filter="">
                <li class="layui-nav-item"><img src="../images/logo.png" class="layui-circle" style="border: 2px solid #A9B7B7;" width="35px" alt=""></li>
                <li class="layui-nav-item">
                    <a href="javascript:;">admin</a>
                    <dl class="layui-nav-child"> <!-- 二级菜单 -->
                        <dd><a href="">个人中心</a></dd>
                        <dd><a href="../logout">退出</a></dd>
                    </dl>
                </li>
                <!-- <li class="layui-nav-item">
                  <a href="" title="消息">
                      <i class="layui-icon" style="top: 1px;">&#xe63a;</i>
                  </a>
                  </li> -->
                <li class="layui-nav-item x-index"><a th:href="@{'../index'}">首页</a></li>
            </ul>
        </div>
    </div>
    <div class="layui-side layui-bg-black x-side">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree site-demo-nav" lay-filter="side">
                <li class="layui-nav-item">
                    <a class="javascript:;" href="javascript:;">
                        <i class="layui-icon" style="top: 3px;">&#xe607;</i><cite>会员管理</cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../user/toUserList'}">
                                <cite>用户列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../user/toAdminList'}">
                                <cite>管理员管理</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../user/toRoleList'}">
                                <cite>角色管理</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../user/toNoteList'}">
                                <cite>短信管理</cite>
                            </a>
                        </dd>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="javascript:;" href="javascript:;">
                        <i class="layui-icon" style="top: 3px;">&#xe62d;</i><cite>商品管理</cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../commodity/toCommodityList'}">
                                <cite>商品列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../commodity/toClassifyList'}">
                                <cite>商品分类</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../commodity/toTradeTrademarkList'}">
                                <cite>品牌列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../commodity/toMoldList'}">
                                <cite>商品类型</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../commodity/toParameterList'}">
                                <cite>商品属性</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../commodity/toPropertyList'}">
                                <cite>参数列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../commodity/toEvaluateList'}">
                                <cite>商品评价</cite>
                            </a>
                        </dd>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="javascript:;" href="javascript:;">
                        <i class="layui-icon" style="top: 3px;">&#xe634;</i><cite>订单管理</cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../order/orderlist'}">
                                <cite>订单列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../invoice/invoicelist'}">
                                <cite>发货单列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../billoflading/BillListAll'}">
                                <cite>提货单列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../aftersale/aftersalelist'}">
                                <cite>售后单列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../return/returnlist'}">
                                <cite>退货单列表</cite>
                            </a>
                        </dd>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="javascript:;" href="javascript:;">
                        <i class="layui-icon" style="top: 3px;">&#xe642;</i><cite>运营管理</cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../Article/Articlelist'}">
                                <cite>文章列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../notice/noticelist'}">
                                <cite>公告列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../ArticleType/ArticleTypelist'}">
                                <cite>文章分类</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../Advertising/Advertisinglist'}">
                                <cite>广告列表</cite>
                            </a>
                        </dd>
                        </dd>
                        <dd class="">
                        <dd class="">
                            <a th:href="@{'../Advertisingspace/Advertisingspacelist'}">
                                <cite>广告位列表</cite>
                            </a>
                        </dd>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="javascript:;" href="javascript:;">
                        <i class="layui-icon" style="top: 3px;">&#xe630;</i><cite>促销管理</cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd class="">
                            <a th:href="@{'../promotion/seckillList'}">
                                <cite>团购秒杀列表</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../coupon/couponList'}">
                                <cite>优惠券列表</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../sales/salesList'}">
                                <cite>促销列表</cite>
                            </a>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="javascript:;" href="javascript:;">
                        <i class="layui-icon" style="top: 3px;">&#xe606;</i><cite>财务管理</cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd class="">
                            <a th:href="@{'../paylist'}">
                                <cite>支付单列表</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../withdlist'}">
                                <cite>提现列表</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../metlist'}">
                                <cite>支付方式列表</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../retlist'}">
                                <cite>退款单列表</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../acclist'}">
                                <cite>账户资金管理</cite>
                            </a>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="javascript:;" href="javascript:;">
                        <i class="layui-icon" style="top: 3px;">&#xe612;</i><cite>控制面板</cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd class="">
                            <a th:href="@{'../explist'}">
                                <cite>导入导出</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../piclist'}">
                                <cite>图片列表</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../stolist'}">
                                <cite>门店列表</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../log/loglist'}">
                                <cite>操作日志</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../logisticsCompany/getLogistics'}">
                                <cite>物流公司列表</cite>
                            </a>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="javascript:;" href="javascript:;">
                        <i class="layui-icon" style="top: 3px;">&#xe613;</i><cite>微信管理</cite>
                    </a>
                    <dl class="layui-nav-child">
                        <dd class="">
                            <a th:href="@{'../official/getOfficial'}">
                                <cite>公众号配置</cite>
                            </a>
                        </dd>
                        <dd class="">
                            <a th:href="@{'../official/getApplet'}">
                                <cite>小程序配置</cite>
                            </a>
                        </dd>
                    </dl>
                </li>
            </ul>
        </div>

    </div>
    <div class="layui-tab layui-tab-card site-demo-title x-main" lay-filter="x-tab" lay-allowclose="true">
        <div class="x-slide_left"></div>
        <!-- <ul class="layui-tab-title">
             <li class="layui-this">
                 我的桌面
                 <i class="layui-icon layui-unselect layui-tab-close">ဆ</i>
             </li>
         </ul>-->
        <div style="padding: 15px;">
            <div class="x-nav">
            <span class="layui-breadcrumb" style="visibility: visible;">
                <a href="">商品管理</a><span lay-separator="">/</span>
                <a href="toMerchandiseList">商品列表</a><span lay-separator="">/</span>
                <a href="toMerchandiseAdd">商品增加</a>
            </span>
                <a class="layui-btn layui-btn-primary" style="line-height:1.6em;margin-top:3px;float:right"
                   onclick="location.reload()" title="刷新">
                    <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
                </a>
            </div>
        </div>
        <div class="layui-upload-list" id="upload" style="position: fixed;">
            <p id="upload_text_logo"></p>
        </div>
        <div style="line-height: 40px">
            <form action="CommodityAdd" method="post" enctype="multipart/form-data" id="form">
                <div class="table-body" id="div1">
                    商品分类:<select name="mold1" id="mold1">
                    <option value="0">请选择分类</option>
                    <option th:each="list:${session.classifyList}" th:value="${list.id}"><span
                            th:text="${list.name}"></span></option>
                </select>
                    <select name="classifyId" id="mold2">
                        <option></option>
                    </select><br/>
                    商品类型:<select name="moldId" id="mold3">
                        <option value="0">请选择分类</option>
                    <option th:each="list:${session.moldList}" th:value="${list.id}"><span
                            th:text="${list.name}"></span></option>
                    </select><br/>
                    商品品牌:<select name="trademarkId" id="mold4">
                    <option value="0">请选择分类</option>
                    <option th:each="list:${session.trademarkList}" th:value="${list.id}"><span
                            th:text="${list.name}"></span></option>
                </select><br/>
                    商品名称:<input type="text" name="name" placeholder="请输入商品名称" class="layui-input">
                    销售价:<input type="number" name="salesPrice" placeholder="请输入销售价" class="layui-input">
                    成本价:<input type="number" name="costPrice" placeholder="请输入市场价" class="layui-input">
                    市场价<input type="number" name="marketPrice" placeholder="请输入成本价" class="layui-input">
                    库存:<input type="number" name="repertory" placeholder="请输入库存" class="layui-input">
                    商品图片:<input type="file" name="files" id="files">
                    <button type="button" class="layui-btn" id="upload_img_logo">商品图片</button>
                    <div class="layui-form-item" style="position: relative;left: 200px;">
                        <button class="layui-btn layui-btn-sm" type="submit" id="modifyBtn">新增</button>
                        <a href="javascript:history.go(-1);" class="layui-btn layui-btn-sm">返回</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="site-mobile-shade">
    </div>
</div>
<script src="../lib/layui/layui.js" charset="utf-8"></script>
<script src="../js/x-admin.js"></script>
<script src="../js/sweetalert-dev.js"></script>
<link rel="stylesheet" href="../css/sweetalert.css" media="all">
<script th:src="@{/webjars/jquery/3.3.1/jquery.min.js}"></script>
<script type="text/javascript">
    $(function () {
        $("#mold2").hide();
        $("[name=files]").hide();
        $("[name=mold1]").change(function () {
            $("#mold2").show();
            var id = $(this).val();
            var twoname = document.getElementById("mold2");
            var option = twoname.getElementsByTagName("option");
            var len = option.length;
            /*for (var i = 0; i < len; i++) {
                twoname.remove(option[i]);
            }*/
            $.getJSON("allname", {"id": id}, function (data) {
                var name2 = $("#mold2");
                name2.html('');
                for (var i = 0; i < data.length; i++) {
                    var id = data[i].id;
                    var name = data[i].name;
                    var option = "<option";
                    option += " value=" + id + ">";
                    option += "" + name + "";
                    option += "</option>";
                    name2.append(option);
                }
            });
        });
        $("#upload_img_logo").click(function () {
            $("[name=files]").click();
        });

        $("#form").submit(function () {
            var classifyId=$("[name=classifyId]").val();
            var moldId=$("[name=moldId]").val();
            var trademarkId=$("[name=trademarkId]").val();
            var name=$("[name=name]").val();
            var salesPrice=$("[name=salesPrice]").val();
            var costPrice=$("[name=costPrice]").val();
            var marketPrice=$("[name=marketPrice]").val();
            var repertory=$("[name=repertory]").val();
            var imgPath=$("[name=files]").val();
            if(classifyId==0){
            swal("您还没有选择商品分类哦!");
                //alert("您还没有选择商品分类哦!");
                return false;
            }else if(moldId==0){
             swal("您还没有选择商品类型哦!");
               // alert("您还没有选择商品类型哦!");
                return false;
            }else if(trademarkId==0){
             swal("您还没有选择品牌哦!");
             //   alert("您还没有选择品牌哦!");
                return false;
            }else if(name=="" || name==null){
            swal("您还没有输入商品名称哦!");
              //  alert("您还没有输入品牌名哦!");
                return false;
            }else if(salesPrice=="" || salesPrice==null){
            swal("您还没有输入销售价哦!");
              //  alert("您还没有输入销售价哦!");
                return false;
            }else if(costPrice=="" || costPrice==null){
             swal("您还没有输入成本价哦!");
                //alert("您还没有输入成本价哦!");
                return false;
            }else if(marketPrice=="" || marketPrice==null){
             swal("您还没有输入市场价哦!");
               // alert("您还没有输入市场价哦!");
                return false;
            }else if(repertory=="" || repertory==null){
             swal("您还没有输入库存哦!");
               // alert("您还没有输入库存哦!");
                return false;
            }else if(imgPath=="" || imgPath==null){
             swal("您还没有选择图片哦!");
               // alert("您还没有选择图片哦!");
                return false;
            }else if(salesPrice<=0){
                swal("您输入的销售价无效哦!");
                 return false;
            }else if(costPrice<=0){
                swal("您输入的成本价无效哦!");
                 return false;
            }else if(marketPrice<=0){
                swal("您输入的市场价无效哦!");
                 return false;
            }else if(repertory<=0){
                swal("您输入的库存无效哦!");
                 return false;
            }
        });
        $("[name=name]").blur(function () {
            var name=$("[name=name]").val();
            $.ajax({
                url:'chackCommodityName',
                data:"name="+name,
                async:false,
                dataType:'json',
                success:function(data){
                    if(data.checking=="exists"){
                     swal("该商品名已经被注册了哦!");
                       // alert("该商品名已经被注册了哦!");
                        $("[name=name]").val("");
                    }
                }
            });
        });

        $(document).on('change', '#files', function () { //PictureUrl为input file 的id
            //console.log(this.files[0]);
            function getObjectURL(file) {
                var url = null;
                if (window.createObjcectURL != undefined) {
                    url = window.createOjcectURL(file);
                } else if (window.URL != undefined) {
                    url = window.URL.createObjectURL(file);
                } else if (window.webkitURL != undefined) {
                    url = window.webkitURL.createObjectURL(file);
                }
                return url;
            }
            var objURL = getObjectURL(this.files[0]);//这里的objURL就是input file的真实路径
            $('#upload').html("<img src='" + objURL + "' alt='Alternate Text' width='340px' height='350px' id='target' />");
        });
    })
</script>
</body>
</html>
